<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/manage' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>添加商品</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="form">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="商品名称">
          <el-input v-model="form.name"/>
        </el-form-item>
        <el-form-item label="商品类别">
          <el-select v-model="form.region" placeholder="请选择商品类别" :multiple="true" :collapse-tags="true">
            <el-option label="类别一" value="shanghai"/>
            <el-option label="类别二" value="beijing"/>
            <el-option label="类别三" value="san"/>
            <el-option label="类别四" value="si"/>
          </el-select>
        </el-form-item>
        <el-form-item label="价格设置">
          <el-radio-group v-model="form.type" @change="priceRadioChange">
            <el-radio label="采用折扣体系"/>
            <el-radio label="设置具体价格"/>
            <el-radio label="设置一口价"/>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="具体价格" class="concretePrice">
          <div class="sell" v-show="sellPriceSetShow">
            <span>零售价</span><el-input><i slot="suffix" class="money">￥</i></el-input>
          </div>
          <div class="prices" v-show="priceSetShow">
            <span>VIP价</span><el-input><i slot="suffix" class="money">￥</i></el-input>
            <span>批发价</span><el-input><i slot="suffix" class="money">￥</i></el-input>
            <span>分销商价</span><el-input><i slot="suffix" class="money">￥</i></el-input>
          </div>
          <div class="once" v-show="oncePriceSetShow">
            <span>一口价</span><el-input><i slot="suffix" class="money">￥</i></el-input>
          </div>
        </el-form-item>
        <el-form-item label="设置底价" class="base-price">
          <el-input/>
        </el-form-item>
        <el-form-item label="商品状态">
          <el-radio-group v-model="form.resource">
            <el-radio label="正常"/>
            <el-radio label="下架"/>
            <el-radio label="删除"/>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="商品描述">
          <el-input type="textarea" v-model="form.desc"></el-input>
        </el-form-item>
        <div class="upload">
          <span style="float: left;color: #606266;margin: 0 12px;line-height: 148px;">商品图片</span>
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove"
            :auto-upload="true"
            :before-upload="uploadClick">
            <i class="el-icon-plus"></i>
          </el-upload>
          <el-dialog :visible.sync="dialogVisible">
            <img width="100%" :src="dialogImageUrl" alt="">
          </el-dialog>
        </div>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: 'goods-add',
  data () {
    return {
      dialogImageUrl: '',
      dialogVisible: false,
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: '采用折扣体系',
        resource: '',
        desc: ''
      },
      priceSetShow: false,
      oncePriceSetShow: false,
      sellPriceSetShow: true
    }
  },
  methods: {
    handleRemove (file, fileList) {
      console.log(file, fileList)
    },
    handlePictureCardPreview (file) {
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    },
    onSubmit () {
      console.log('submit')
      console.log(this.form)
    },
    priceRadioChange (label) {
      if (label === '设置具体价格') {
        this.priceSetShow = true
        this.oncePriceSetShow = false
        this.sellPriceSetShow = false
      } else if (label === '设置一口价') {
        this.priceSetShow = false
        this.oncePriceSetShow = true
        this.sellPriceSetShow = false
      } else {
        this.priceSetShow = false
        this.oncePriceSetShow = false
        this.sellPriceSetShow = true
      }
    },
    uploadClick () {
      alert('xxx')
    }
  }
}
</script>

<style scoped>
  .form{
    width: 75%;
  }
  .concretePrice span{
    margin-right: 8px;
  }
  .concretePrice .el-input{
    width: 120px;
    margin-right: 30px;
  }
  .once, .base-price{
    width: 240px;
  }
  .upload{
    margin-bottom: 20px;
  }
</style>
